// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let { name, point, beginTime, endTime } = event
  var success = false
  var message = "添加失败"
  const db = cloud.database()

  await db.collection('activity').add({
    data: {
      name: name,
      point: parseInt(point),
      beginTime: beginTime,
      endTime: endTime,
      isActivity: true,
    }
  }).then(res => {
    success = true
    message = "添加成功"
  }, error => {
    success = false
    message = "添加失败"
  })
  return {
    success: success,
    message: message
  }
}